<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="刘清政">
  <meta name="keyword" content="hexo-theme">
  
    <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
      6-Docker之网络 | Justin-刘清政的博客
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/css/plugins/gitment.css">

  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
    
<script src="/js/gitment.js"></script>

  
  

  
<meta name="generator" content="Hexo 4.2.0"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>Justin-刘清政的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于我</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于我</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>6-Docker之网络</h2>



  <p class="post-date">2019-03-28</p>
    <!-- 不蒜子统计 -->
    <span id="busuanzi_container_page_pv" style='display:none' class="">
        <i class="icon-smile icon"></i> 阅读数：<span id="busuanzi_value_page_pv"></span>次
    </span>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h2 id="一-Docker-网络管理简介"><a href="#一-Docker-网络管理简介" class="headerlink" title="一 Docker 网络管理简介"></a>一 Docker 网络管理简介</h2><h3 id="1-1-为什么要Docker网络管理"><a href="#1-1-为什么要Docker网络管理" class="headerlink" title="1.1 为什么要Docker网络管理"></a>1.1 为什么要Docker网络管理</h3><blockquote>
<p>容器的网络默认与宿主机、与其他容器都是相互隔离。</p>
<p>​    •容器中可以运行一些网络应用(如nginx、web应用、数据库等)，如果要让外部也可以访问这些容器内运行的网络应用，那么就需要配置网络来实现。</p>
<p>​    •有可能有的需求下，容器不想让它的网络与宿主机、与其他容器隔离。</p>
<p>​    •有可能有的需求下，容器根本不需要网络。</p>
<p>​    •有可能有的需求下，容器需要更高的定制化网络（如定制特殊的集群网络、定制容器间的局域网）。</p>
<p>​    •有可能有的需求下， 容器数量特别多，体量很大的一系列容器的网络管理如何</p>
<p>​    •……</p>
<p>因此容器的网络管理是非常重要的</p>
</blockquote>
<h3 id="1-2-Docker中有哪些网络驱动模式"><a href="#1-2-Docker中有哪些网络驱动模式" class="headerlink" title="1.2 Docker中有哪些网络驱动模式"></a>1.2 Docker中有哪些网络驱动模式</h3><blockquote>
<p>Docker有五种网络驱动模式</p>
<p>​    •bridge network 模式（网桥）：默认的网络模式。类似虚拟机的nat模式</p>
<p>​    •host network 模式（主机）：容器与宿主机之间的网络无隔离，即容器直接使用宿主机网络</p>
<p>​    •None network 模式：容器禁用所有网络。</p>
<p>​    •Overlay network 模式（覆盖网络）： 利用VXLAN实现的bridge模式</p>
<p>​    •Macvlan network 模式：容器具备Mac地址，使其显示为网络上的物理设备</p>
</blockquote>
<h2 id="二-Docker-网络管理命令"><a href="#二-Docker-网络管理命令" class="headerlink" title="二 Docker 网络管理命令"></a>二 Docker 网络管理命令</h2><h3 id="2-1-查看网络-–-docker-network-ls"><a href="#2-1-查看网络-–-docker-network-ls" class="headerlink" title="2.1 查看网络 – docker network ls"></a>2.1 查看网络 – docker network ls</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 作用：</span></span><br><span class="line">	查看已经建立的网络对象</span><br><span class="line"><span class="comment"># 命令格式：</span></span><br><span class="line">	docker network ls [OPTIONS]</span><br><span class="line"><span class="comment"># 命令参数(OPTIONS)：</span></span><br><span class="line">	-f, --filter filter   		过滤条件(如 <span class="string">'driver=bridge’)</span></span><br><span class="line"><span class="string">	    --format string   	格式化打印结果</span></span><br><span class="line"><span class="string">	    --no-trunc        	不缩略显示</span></span><br><span class="line"><span class="string">	-q, --quiet          	 	只显示网络对象的ID</span></span><br><span class="line"><span class="string"># 注意：</span></span><br><span class="line"><span class="string">	默认情况下，docker安装完成后，会自动创建bridge、host、none三种网络驱动	</span></span><br><span class="line"><span class="string"># 命令演示</span></span><br><span class="line"><span class="string">                                 </span></span><br><span class="line"><span class="string">docker network ls</span></span><br><span class="line"><span class="string">docker network ls --no-trunc</span></span><br><span class="line"><span class="string">docker network ls -f '</span>driver=host<span class="string">'</span></span><br></pre></td></tr></table></figure>

<h3 id="2-2-创建网络-–-docker-network-create"><a href="#2-2-创建网络-–-docker-network-create" class="headerlink" title="2.2 创建网络 – docker network create"></a>2.2 创建网络 – docker network create</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 作用：</span></span><br><span class="line">	创建新的网络对象</span><br><span class="line"><span class="comment"># 命令格式：</span></span><br><span class="line">	docker network create [OPTIONS] NETWORK</span><br><span class="line"><span class="comment"># 命令参数(OPTIONS)：</span></span><br><span class="line">	-d, --driver string        		指定网络的驱动(默认 <span class="string">"bridge"</span>)</span><br><span class="line">	    --subnet strings       		指定子网网段(如<span class="number">192.168</span><span class="number">.0</span><span class="number">.0</span>/<span class="number">16</span>、<span class="number">172.88</span><span class="number">.0</span><span class="number">.0</span>/<span class="number">24</span>)</span><br><span class="line">	    --ip-range strings     		执行容器的IP范围，格式同subnet参数</span><br><span class="line">	    --gateway strings      		子网的IPv4 <span class="keyword">or</span> IPv6网关，如(<span class="number">192.168</span><span class="number">.0</span><span class="number">.1</span>)</span><br><span class="line"><span class="comment"># 注意：</span></span><br><span class="line">	host和none模式网络只能存在一个</span><br><span class="line">	docker自带的overlay 网络创建依赖于docker swarm(集群负载均衡)服务</span><br><span class="line">	<span class="number">192.168</span><span class="number">.0</span><span class="number">.0</span>/<span class="number">16</span> 等于 <span class="number">192.168</span><span class="number">.0</span><span class="number">.0</span>~<span class="number">192.168</span><span class="number">.255</span><span class="number">.255</span>    <span class="number">192.168</span><span class="number">.8</span><span class="number">.0</span>/<span class="number">24</span></span><br><span class="line">	<span class="number">172.88</span><span class="number">.0</span><span class="number">.0</span>/<span class="number">24</span> 等于 <span class="number">172.88</span><span class="number">.0</span><span class="number">.0</span>~<span class="number">172.88</span><span class="number">.0</span><span class="number">.255</span></span><br><span class="line"><span class="comment"># 命令演示</span></span><br><span class="line">docker network ls</span><br><span class="line">docker network create -d bridge my-bridge</span><br><span class="line">docker network ls</span><br></pre></td></tr></table></figure>

<h3 id="2-3-网络删除-–-docker-network-rm"><a href="#2-3-网络删除-–-docker-network-rm" class="headerlink" title="2.3 网络删除 – docker network rm"></a>2.3 网络删除 – docker network rm</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 作用：</span></span><br><span class="line">	删除一个或多个网络</span><br><span class="line"><span class="comment"># 命令格式：</span></span><br><span class="line">	docker network rm NETWORK [NETWORK...]</span><br><span class="line"><span class="comment"># 命令参数(OPTIONS)：</span></span><br><span class="line">	无</span><br></pre></td></tr></table></figure>

<h3 id="2-4-查看网络详细信息-–-docker-network-inspect"><a href="#2-4-查看网络详细信息-–-docker-network-inspect" class="headerlink" title="2.4 查看网络详细信息 – docker network inspect"></a>2.4 查看网络详细信息 – docker network inspect</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 作用：</span></span><br><span class="line">	查看一个或多个网络的详细信息</span><br><span class="line"><span class="comment"># 命令格式：</span></span><br><span class="line">	docker network inspect [OPTIONS] NETWORK [NETWORK...]</span><br><span class="line">      或者 docker inspect [OPTIONS] NETWORK [NETWORK...]</span><br><span class="line"><span class="comment"># 命令参数(OPTIONS)：</span></span><br><span class="line">	-f, --format string   	根据format输出结果</span><br></pre></td></tr></table></figure>

<h3 id="2-5-使用网络-–-docker-run-–network"><a href="#2-5-使用网络-–-docker-run-–network" class="headerlink" title="2.5 使用网络 – docker run –network"></a>2.5 使用网络 – docker run –network</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 作用：</span></span><br><span class="line">	为启动的容器指定网络模式</span><br><span class="line"><span class="comment"># 命令格式：</span></span><br><span class="line">	docker run/create --network NETWORK</span><br><span class="line"><span class="comment"># 命令参数(OPTIONS)：</span></span><br><span class="line">	无</span><br><span class="line"><span class="comment"># 注意：</span></span><br><span class="line">	默认情况下，docker创建或启动容器时，会默认使用名为bridge的网络</span><br></pre></td></tr></table></figure>

<h3 id="2-6-网络连接与断开-–-docker-network-connect-disconnect"><a href="#2-6-网络连接与断开-–-docker-network-connect-disconnect" class="headerlink" title="2.6 网络连接与断开 – docker network connect/disconnect"></a>2.6 网络连接与断开 – docker network connect/disconnect</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 作用：</span></span><br><span class="line">	将指定容器与指定网络进行连接或者断开连接</span><br><span class="line"><span class="comment"># 命令格式：</span></span><br><span class="line">	docker network connect [OPTIONS] NETWORK CONTAINER</span><br><span class="line">	docker network disconnect [OPTIONS] NETWORK CONTAINER</span><br><span class="line"><span class="comment"># 命令参数(OPTIONS)：</span></span><br><span class="line">	-f, --force   		强制断开连接(用于disconnect)</span><br></pre></td></tr></table></figure>



<h2 id="三-Docker-网络模式简介"><a href="#三-Docker-网络模式简介" class="headerlink" title="三 Docker 网络模式简介"></a>三 Docker 网络模式简介</h2><h3 id="3-1-bridge-网络模式-一"><a href="#3-1-bridge-网络模式-一" class="headerlink" title="3.1 bridge 网络模式(一)"></a>3.1 bridge 网络模式(一)</h3><blockquote>
<p>特点：</p>
<p>​    •宿主机上需要单独的bridge网卡，如默认docker默认创建的docker0。</p>
<p>​    •容器之间、容器与主机之间的网络通信，是借助为每一个容器生成的一对veth pair虚拟网络设备对，进行通信的。一个在容器上，另一个在宿主机上。</p>
<p>​    •每创建一个基于bridge网络的容器，都会自动在宿主机上创建一个veth**虚拟网络设备。</p>
<p>​    •外部无法直接访问容器。需要建立<strong>端口映射</strong>才能访问。</p>
<p>​    •容器借由veth虚拟设备通过如docker0这种bridge网络设备进行通信。</p>
<p>​    •每一容器具有单独的IP</p>
</blockquote>
<img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfm88du0j30jw0bwac2.jpg" alt="image-20200331004402089" style="zoom:67%;" />

<h3 id="3-2-bridge-网络模式（二）-–-端口映射"><a href="#3-2-bridge-网络模式（二）-–-端口映射" class="headerlink" title="3.2 bridge 网络模式（二） – 端口映射"></a>3.2 bridge 网络模式（二） – 端口映射</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 作用：</span></span><br><span class="line">	启动的容器时，为容器进行端口映射</span><br><span class="line"><span class="comment"># 命令格式：</span></span><br><span class="line">	docker run/create -P …</span><br><span class="line">      或者 docker run/create –p …</span><br><span class="line"><span class="comment"># 命令参数(OPTIONS)：</span></span><br><span class="line">	-P, --publish-all		将容器内部所有暴露端口进行随机映射</span><br><span class="line">	-p, --publish list 	手动指定端口映射</span><br><span class="line"><span class="comment"># 注意：</span></span><br><span class="line">	-p [HOST_IP]:[HOST_PORT]:CONTAINER_PORT</span><br><span class="line">	如：-p ::<span class="number">80</span>		将容器的<span class="number">80</span>端口随机(端口)映射到宿主机任意IP</span><br><span class="line">	       -p :<span class="number">8000</span>:<span class="number">6379</span> 	将容器的<span class="number">6379</span>端口映射到宿主机任意IP的<span class="number">8000</span>端口</span><br><span class="line">	       -p <span class="number">192.168</span><span class="number">.5</span><span class="number">.1</span>::<span class="number">3306</span>	将容器的<span class="number">3306</span>端口随机(端口)映射到宿主机的<span class="number">192.168</span><span class="number">.5</span><span class="number">.1</span>IP上</span><br></pre></td></tr></table></figure>

<img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfna33szj30ew0actam.jpg" alt="image-20200331004503199" style="zoom:67%;" />

<h3 id="3-3-host-网络模式"><a href="#3-3-host-网络模式" class="headerlink" title="3.3 host 网络模式"></a>3.3 host 网络模式</h3><blockquote>
<p>特点：</p>
<p>​    •容器完全共享宿主机的网络。网络没有隔离。宿主机的网络就是容器的网络。</p>
<p>​    •容器、主机上的应用所使用的端口不能重复。例如：如果宿主机已经占用了8090端口，那么任何一个host模式的容器都不可以使用8090端口了；反之同理。</p>
<p>​    •外部可以直接访问容器，不需要端口映射。</p>
<p>​    •容器的IP就是宿主机的IP</p>
</blockquote>
<img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfo8tw8fj30lo08qmz2.jpg" alt="image-20200331004558144" style="zoom:67%;" />

<h3 id="3-4-特殊host-网络模式（Container网络模式）"><a href="#3-4-特殊host-网络模式（Container网络模式）" class="headerlink" title="3.4 特殊host 网络模式（Container网络模式）"></a>3.4 特殊host 网络模式（Container网络模式）</h3><blockquote>
<p>•Container网络模式，其实就是容器共享其他容器的网络。</p>
<p>•相当于该容器,，在网络层面上，将其他容器作为“主机”。它们之间的网络没有隔离。</p>
<p>•这些容器之间的特性同host模式。</p>
<p>使用方法：</p>
<p>​     <strong>Docker</strong> <strong>run/create</strong> <strong>–network</strong> <strong>container:CONTAINER</strong> <strong>…</strong></p>
</blockquote>
<img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfozwznkj30g60awq3w.jpg" alt="image-20200331004641712" style="zoom:67%;" />

<h3 id="3-5-none-网络模式"><a href="#3-5-none-网络模式" class="headerlink" title="3.5  none 网络模式"></a>3.5  none 网络模式</h3><blockquote>
<p>特点：</p>
<p>​    •容器上没有网络，也无任何网络设备。</p>
<p>​    •如果需要使用网络，需要用户自行安装与配置。</p>
<p>应用场景</p>
<p>​    •该模式适合需要高度定制网络的用户使用。</p>
</blockquote>
<h3 id="3-6-overlay-网络模式（一）"><a href="#3-6-overlay-网络模式（一）" class="headerlink" title="3.6 overlay 网络模式（一）"></a>3.6 overlay 网络模式（一）</h3><blockquote>
<p>•Overlay 网络，也称为覆盖网络。</p>
<p>•Overlay 网络的实现方式和方案有多种。Docker自身集成了一种，基于VXLAN隧道技术实现。</p>
<p>•Overlay 网络主要用于实现跨主机容器之间的通信。</p>
<p>应用场景：需要管理成百上千个跨主机的容器集群的网络时</p>
</blockquote>
<h3 id="3-7-overlay-网络模式（二）-了解TCP-IP协议栈"><a href="#3-7-overlay-网络模式（二）-了解TCP-IP协议栈" class="headerlink" title="3.7 overlay 网络模式（二）- 了解TCP/IP协议栈"></a>3.7 overlay 网络模式（二）- 了解TCP/IP协议栈</h3><img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfqmuv86j30jm0hkq7a.jpg" alt="image-20200331004816849" style="zoom:67%;" />

<h3 id="3-8-overlay-网络模式（三）-实现原理"><a href="#3-8-overlay-网络模式（三）-实现原理" class="headerlink" title="3.8 overlay 网络模式（三）- 实现原理"></a>3.8 overlay 网络模式（三）- 实现原理</h3><img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfrhw54pj30is07k410.jpg" alt="image-20200331004905939" style="zoom:50%;" />

<img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfrr1nbsj30im0eaac8.jpg" alt="image-20200331004921447" style="zoom:67%;" />

<h3 id="3-9-macvlan-网络模式"><a href="#3-9-macvlan-网络模式" class="headerlink" title="3.9 macvlan 网络模式"></a>3.9 macvlan 网络模式</h3><blockquote>
<p>•macvlan网络模式，最主要的特征就是他们的通信会直接基于mac地址进行转发。</p>
<p>•这时宿主机其实充当一个二层交换机。Docker会维护着一个MAC地址表，当宿主机网络收到一个数据包后，直接根据mac地址找到对应的容器，再把数据交给对应的容器。</p>
<p>•容器之间可以直接通过IP互通，通过宿主机上内建的虚拟网络设备（创建macvlan网络时自动创建），但与主机无法直接利用IP互通。</p>
<p>应用场景：由于每个外来的数据包的目的mac地址就是容器的mac地址，这时每个容器对于外面网络来说就相当于一个真实的物理网络设备。因此当需要让容器来的网络看起来是一个真实的物理机时，使用macvlan模式</p>
</blockquote>
<img src="https://tva1.sinaimg.cn/large/00831rSTly1gdcfsiczv9j30fw0g6dh3.jpg" alt="image-20200331005004448" style="zoom:67%;" />

<h2 id="四-总结"><a href="#四-总结" class="headerlink" title="四 总结"></a>四 总结</h2><blockquote>
<p>重点掌握：</p>
<p>​    •bridge网络、host网络、Container网络模式的原理和使用（应用得较多，且host网络性能最优）。</p>
<p>​    •docker network命令的使用</p>
<p>了解：</p>
<p>​    •none网络的效果</p>
<p>​    •overlay网络、macvlan网络的原理。（使用起来难度较大）</p>
</blockquote>
</section>
    <!-- Tags START -->
    
      <div class="tags">
        <span>Tags:</span>
        
  <a href="/tags#Linux" >
    <span class="tag-code">Linux</span>
  </a>

      </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/linux/Docker/4-Docker%E4%B9%8B%E5%AE%B9%E5%99%A8/">
        <span class="nav-arrow">← </span>
        
          4-Docker之容器
        
      </a>
    
    
      <a class="nav-right" href="/linux/Docker/1-Docker%E4%B9%8B%E4%BB%8B%E7%BB%8D/">
        
          1-Docker介绍与安装
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">点击上方按钮,请我喝杯咖啡！</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Gitment START -->
      <div id="comments"></div>
      <!-- Gitment END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
  <!-- 不蒜子统计 -->
    <strong class="toc-title">目录</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#一-Docker-网络管理简介"><span class="toc-nav-text">一 Docker 网络管理简介</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-1-为什么要Docker网络管理"><span class="toc-nav-text">1.1 为什么要Docker网络管理</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-2-Docker中有哪些网络驱动模式"><span class="toc-nav-text">1.2 Docker中有哪些网络驱动模式</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#二-Docker-网络管理命令"><span class="toc-nav-text">二 Docker 网络管理命令</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-1-查看网络-–-docker-network-ls"><span class="toc-nav-text">2.1 查看网络 – docker network ls</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-2-创建网络-–-docker-network-create"><span class="toc-nav-text">2.2 创建网络 – docker network create</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-3-网络删除-–-docker-network-rm"><span class="toc-nav-text">2.3 网络删除 – docker network rm</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-查看网络详细信息-–-docker-network-inspect"><span class="toc-nav-text">2.4 查看网络详细信息 – docker network inspect</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-5-使用网络-–-docker-run-–network"><span class="toc-nav-text">2.5 使用网络 – docker run –network</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-6-网络连接与断开-–-docker-network-connect-disconnect"><span class="toc-nav-text">2.6 网络连接与断开 – docker network connect&#x2F;disconnect</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#三-Docker-网络模式简介"><span class="toc-nav-text">三 Docker 网络模式简介</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-1-bridge-网络模式-一"><span class="toc-nav-text">3.1 bridge 网络模式(一)</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-2-bridge-网络模式（二）-–-端口映射"><span class="toc-nav-text">3.2 bridge 网络模式（二） – 端口映射</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-3-host-网络模式"><span class="toc-nav-text">3.3 host 网络模式</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-4-特殊host-网络模式（Container网络模式）"><span class="toc-nav-text">3.4 特殊host 网络模式（Container网络模式）</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-5-none-网络模式"><span class="toc-nav-text">3.5  none 网络模式</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-6-overlay-网络模式（一）"><span class="toc-nav-text">3.6 overlay 网络模式（一）</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-7-overlay-网络模式（二）-了解TCP-IP协议栈"><span class="toc-nav-text">3.7 overlay 网络模式（二）- 了解TCP&#x2F;IP协议栈</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-8-overlay-网络模式（三）-实现原理"><span class="toc-nav-text">3.8 overlay 网络模式（三）- 实现原理</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-9-macvlan-网络模式"><span class="toc-nav-text">3.9 macvlan 网络模式</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#四-总结"><span class="toc-nav-text">四 总结</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://www.liuqingzheng.top/linux/Docker/6-Docker之网络/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>



  <script>
    var gitmentConfig = "liuqingzheng";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "6-Docker之网络",
        owner: "liuqingzheng",
        repo: "FuckBlog",
        oauth: {
          client_id: "32a4076431cf39d0ecea",
          client_secret: "94484bd79b3346a949acb2fda3c8a76ce16990c6"
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  </script>




    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
<!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
     本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
     本站访客数<span id="busuanzi_value_site_uv"></span>人
</span>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



  <p class="copyright">
    &copy; 2021 | Proudly powered by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank">小猿取经</a>
    <br>
    Theme by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank" rel="noopener">小猿取经</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>





<!-- Baidu Tongji -->

<script>
    var _baId = 'c5fd96eee1193585be191f318c3fa725';
    // Originial
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>


<script src="/js/script.js"></script>


<script src="/js/search.js"></script>


<script src="/js/load.js"></script>



  <span class="local-search local-search-google local-search-plugin" style="right: 50px;top: 70px;;position:absolute;z-index:2;">
      <input type="search" placeholder="站内搜索" id="local-search-input" class="local-search-input-cls" style="">
      <div id="local-search-result" class="local-search-result-cls"></div>
  </span>


  </body>
</html>